package javaxml;

/*!
    * \file      ReportException.java
    * \author    Tony
    * \version   1.0
    * \date      2010 - 2011
    *
 */

import java.io.PrintWriter;
import java.io.StringWriter;
import org.apache.log4j.Logger;


public class ReportException extends Exception
{        
    private static final long serialVersionUID = 1L;
    private static Logger log4j = Logger.getRootLogger();
    protected Exception _Ex = null;
    protected Object _object;
        

    public ReportException(Object p_objet, Exception e)
    {
            super(e.getMessage());
            log4j.error(e.getMessage());
            
            _Ex = e;
            _object = p_objet;
    }

    public ReportException(Object p_objet, String p_message)
    {
            super(p_message);
            log4j.error(p_message);
            log4j.error(p_objet.toString());
            
            _Ex = null;
            _object = p_objet;
    }
    
    protected String stack2string(Exception e) {
      try {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        log4j.error(e.getMessage());
        return "------\r\n" + sw.toString() + "------\r\n";
      }
      catch(Exception e2) {
        return "bad stack2string";
      }
     }
}
